import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base_plugin_example/app_manager/app_router_manager.dart';
import 'package:flutter_base_plugin_example/app_manager/app_routers.dart';

class CommonDialog {
  ///未登录提示
  static void notLoadingDialog(BuildContext context) {
    showCupertinoDialog(
      context: context,
      // barrierDismissible: false,
      builder: (context) {
        return CupertinoAlertDialog(
          content: Text("未登录，马上去登陆～～～"),
          actions: <Widget>[
            FlatButton(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
                AppRoutesManager.navigateTo(context, AppRouters.login);
              },
            ),
          ],
        );
      },
    ).then((value) => print(value.toString()));
  }

  ///退出登陆登录提示
  static void loginOutDialog(BuildContext context, Function onTap) {
    showCupertinoDialog(
      context: context,
      // barrierDismissible: false,
      builder: (context) {
        return CupertinoAlertDialog(
          content: Text("是否退出登录？"),
          actions: <Widget>[
            FlatButton(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
                onTap();
              },
            ),
          ],
        );
      },
    ).then((value) => print(value.toString()));
  }

  ///删除提示
  static void deleteDialog(BuildContext context,
      {String? message, Function? onTap}) {
    showCupertinoDialog(
      context: context,
      // barrierDismissible: false,
      builder: (context) {
        return CupertinoAlertDialog(
          content: Text(message ?? "未填写"),
          actions: <Widget>[
            FlatButton(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
                onTap;
              },
            ),
          ],
        );
      },
    ).then((value) => print(value.toString()));
  }
}
